package app.controller.mediator
{
	import app.model.global.ApplicationModel;
	
	import com.gaiaframework.debug.GaiaDebug;
	
	import org.robotlegs.mvcs.Mediator;
	import app.view.event.AlertEvent;
	import app.view.helper.AlertInterface;
	
	public class AlertMediator extends Mediator
	{
		[Inject]
		public var alert:AlertInterface;
		
		[Inject]
		public var appModel:ApplicationModel;
		
		[PostConstruct]
		public function init():void
		{
			//alert.init();
		}
		
		override public function onRegister():void
		{
			GaiaDebug.log('AlertMediator.onRegister');
			
			addViewListener(AlertEvent.HIDE, onHideAlert)
			
			eventMap.mapListener(eventDispatcher, AlertEvent.SHOW, showAlert);
			eventMap.mapListener(eventDispatcher, AlertEvent.HIDE, hideAlert);
		}
		
		private function onHideAlert(e:AlertEvent):void
		{
			GaiaDebug.log('AlertMediator.onHideAlert');
			dispatch(e);
		}
		
		private function showAlert(e:AlertEvent):void
		{
			GaiaDebug.log('AlertMediator.showAlert');
			alert.show(appModel.currentAlert);
		}
		private function hideAlert(e:AlertEvent):void
		{
			GaiaDebug.log('AlertMediator.hideAlert');
			alert.hide();
		}
	}
}